<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="current"></div>
    <div id="tips">已使用 00小时00分00秒</div>
</body>

</html>
<script>
    Date.prototype.format = function (format) {
        var args = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
            "S": this.getMilliseconds()
        };
        if (/(y+)/.test(format))
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var i in args) {
            var n = args[i];
            if (new RegExp("(" + i + ")").test(format))
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
        }
        return format;
    };
    var date = new Date();
    document.getElementById("current").innerHTML = "【" + date.format("yyyy-MM-dd hh:mm:ss") + "】";
    var indate = date;
    setInterval("showTime()", 5000);
    function showTime() {
        var todate = new Date();
        var timelong = todate - indate;
        var h = parseInt(timelong / 3600000, 10);
        var m = parseInt(timelong % 3600000 / 60000, 10);
        var s = parseInt(timelong % 60000 / 1000);
        h = check(h); m = check(m); s = check(s);
        document.getElementById("tips").innerHTML = "已过 " + h + "小时" + m + "分" + s + "秒";
    }
    function check(x) {
        return x < 10 ? '0' + x : x;
    }
</script>